package com.codefish.codefishseckill.security;

import com.codefish.codefishseckill.utils.ResponseUtil;
import com.codefish.codefishseckill.vo.RespBeanFactory;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 未登录或登录过期处理类
 *
 * @author <a href='https://gitee.com/hzf2281'>codefish</a>
 * @version 1.0.0
 * @since 2022/08/31 上午 10:23
 */
@Component
public class MyUnLoginHandler implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        //ResponseUtil.out(response, RespBeanFactory.denied("用户未登录或登录已过期"));
        response.sendRedirect("/login");
    }
}
